require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
// var userInfo=JSON.parse(localStorage.getItem("userInfo"));
var vm = new Vue({
    el:"#circleInfo",
    data:{
        isContinuity:true,
        isShow:false,
        uid:"",//用户id
        circleId:"",//圈子id
        type:"",
        groupInfo:{},
        state:"",
        square:"",
        membersLength:"",
        remind:"",
        goodslength:"",
        pop: {
            question: "您确定要退出圈子？",
            show: false
        }
    },
    mounted:function(){
        this.searchObject = this.getQueryStringArgs();
        this.circleId=this.searchObject&&this.searchObject.circleId;
        this.uid=this.searchObject&&this.searchObject.uid;
        this.type=this.searchObject&&this.searchObject.type;
        this.square=this.searchObject&&this.searchObject.square;
        this.getGroupInfo();
    },
    methods:{
        //后退
        getBack: function () {
            //history.go(-1);
            location.href="/friend/circleBar?type=2&circleId="+this.circleId+"&uid="+this.uid
            // if(this.square==1){
            //     location.href="/friend/circleSquare";
            // }else{
            //     location.href="/friend?indexs=3";
            // }
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //圈子贴吧信息
        getGroupInfo:function(){
            var that=this;
            var data={
                loginUid:that.uid,
                circleId:that.circleId
            };
            this.ajax({url:"/friend/getGroupInfo",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.groupInfo=b.json.data;
                    that.goodslength=that.groupInfo.products.length;
                    that.state=that.groupInfo.state;
                    that.remind=that.groupInfo.remind;
                }else{
                    vm.$refs.prompt.toast("获取圈子信息失败！")
                }
            });
        },
        //通过用户id 加入圈子
        joinGroup:function(){
            var that=this;
            var data={
                loginUid:that.uid,
                circleId:that.circleId
            };
            this.ajax({url:"/friend/joinGroup",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0){
                    vm.$refs.prompt.toast("加入成功！");
                    that.state=2;
                }else{
                    vm.$refs.prompt.toast("加入圈子失败！")
                }
            });
        },
        getNext:function(num){
            var path;
            if(num==1){
                path="/friend?type="+this.type+"&circleId="+this.circleId+"&uid="+this.uid;
            }else if(num==2){
                path="/friend/circleMember?circleId="+this.circleId+"&uid="+this.uid+"&isMain="+this.groupInfo.isMain;
            }else if(num==3){
                path="/friend/circleSetup?circleId="+this.circleId+"&uid="+this.uid+"&isMain="+this.groupInfo.isMain;
            }else if(num==4){
                path="/friend/circleProducts?circleId="+this.circleId+"&uid="+this.uid+"&isMain="+this.groupInfo.isMain;
            }
            location.href=path;
        },
        getPost:function(postId){
            var path="/friend/postDetails?postId="+postId+"&uid="+this.uid;
            location.href=path;
        },
        //显示隐藏
        // getIsshow:function(){
        //     this.isShow=!this.isShow;
        // },
        //是否提醒
        updateGroupRemind:function(){
            var that=this;
            var data={
                loginUid:that.uid,
                circleId:that.circleId
            };
            if(that.remind==0){
                data.remind=1;
            }else{
                data.remind=0;
            }
            this.ajax({url:"/friend/updateGroupRemind",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0){
                    if(that.remind==0){
                        that.remind=1;
                    }else{
                        that.remind=0;
                    }
                    vm.$refs.prompt.toast("修改成功！");
                }else{
                    vm.$refs.prompt.toast("修改失败！")
                }
            });
        },
        //是否显示弹框
        getIsClassify:function(){
            this.pop.show=!this.pop.show;
        },
        quitGroup:function(){
            var that=this;
            var data={
                loginUid:that.uid,
                circleId:that.circleId
            };
            this.ajax({url:"/friend/quitGroup",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0){
                    vm.getBack();
                    //that.state=1;
                }else{
                    vm.$refs.prompt.toast("退圈子失败！")
                }
            });
        },
        //个人中心
        getUser:function(item){
            console.log(item);
            location.href="/userHomepage?id="+item;
        }
    }
});